
var validStringAlpha = "^([a-zA-Z]+ ?)+$";
var validData = "^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[12][0-9]{3}$";
var validHora = "^([01][0-9]|2[0-3]):[0-5][0-9]$";
var validRG = "^[0-9]\.[0-9]{3}\.[0-9]{3}-[0-9]$";
var validCPF = "^^[0-9]{3}.?[0-9]{3}.?[0-9]{3}-?[0-9]{2}$";
var validEmail = "^[A-Za-z0-9\\._-]+@[A-Za-z]+\\.[A-Za-z]+$";
var validFone = "^\(\d{2}\)\d{4}-\d{4}$";
var validInteiro = "^[0-9]+$";
var validNotNull = ".";

var camposErrados = {};

var renderError = function() {
    var e = document.getElementById('erro');
    document.getElementById('erro').style.display = "block";
    e.innerHTML = "";
   
    for (var label in camposErrados) {
        if(camposErrados[label]){
            e.innerHTML += "Campo " + label + " é inválido<br/>";            
        }
    }
};

var validate = function(campo,padrao,label){
    var regex = new RegExp(padrao);    
    if (!regex.test(campo.value)){        
        camposErrados[label] = true; 
        campo.style.border = "1px solid red";
    }else{
        document.getElementById("erro").innerHTML = " ";
        camposErrados[label] = false;
        campo.style.border = "1px solid green";
    }
    
    renderError();
    
};
